/**
 ********************************************************************
 * @author roocket
 * @file    main.c
 * @version V0.0.0
 * @date    2024/3/22
 * @brief   This file is to indicate main functions. 
 * @attention Code file rules:
 * rule: file encoding use UTF8;
 * rule: max line length 120 characters;
 * rule: line separator \r\n;
 * rule: use clion auto code format tool.
 */

#include "pwm.h"

int main(void)
{
    int res;
    int fd;

    struct pwm_controller pwm = 
    {
        .node = 0,
        .period = 1000000,
        .duty_cycle = 500000,
        .which_chip = 1,
        .enable = 0,
        .polarity = "normal"
    };
    fd = pwm_controller_init(&pwm);
    if (-1 == fd) {
        perror("pwm controller init error");
        return -1;
    }

    /* do what to do */
    res = pwm_controller_start(fd);
    if (-1 == res) {
        perror("pwm controller start error");
        return -1;
    }

    sleep(10);
    
    res = pwm_controller_stop(fd);
    if (-1 == res) {
        perror("pwm controller stop error");
        return -1;
    }

    res = pwm_controller_deinit(&pwm);
    if (-1 == res) {
        perror("pwm controller deinit error");
        return -1;
    }
    return 0;
}